﻿namespace DangerousRiver
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Media;
    using System.Text;
    using System.Threading;

    class SoundEngine
    {
        //The music player used for playing all the sounds
        static SoundPlayer musicPlayer;

        /// <summary>
        /// Plays the background music on loop
        /// </summary>
        public static void PlayBackGroundMusicLoop()
        {
            musicPlayer = new SoundPlayer("../../Sounds/backgroundMusic.wav");
            musicPlayer.PlayLooping();
        }

        /// <summary>
        /// This plays the end game music on loop
        /// Is used after all lives are lost
        /// </summary>
        public static void PlayEndGameMusicLoop(object ignored)
        {
            musicPlayer.Stop();
            musicPlayer = new SoundPlayer("../../Sounds/gameOver.wav");
            musicPlayer.PlayLooping();
        }

        //The following methods are supposed to be run and after that 
        //the background music should start playing again
        //are used in the main class like so:
        //ThreadPool.QueueUserWorkItem(DangerousRiver.SoundEngine.Method);
        //Where `Method` is one of the methods below
        //That's why they have to have an object parameter (which is ignored)        

        /// <summary>
        /// Plays a crashing sound when the boat crashes
        /// </summary>
        public static void PlayCrashSound(object ignored)
        {
            musicPlayer.Stop();
            musicPlayer = new SoundPlayer("../../Sounds/crashSound.wav");

            musicPlayer.PlaySync();
            PlayBackGroundMusicLoop();
        }

        /// <summary>
        /// Plays a bad sound for getting a negative bonus
        /// Is currently NOT used
        /// </summary>
        public static void PlayBadBoost(object ignored)
        {
            musicPlayer.Stop();
            musicPlayer = new SoundPlayer("../../Sounds/getBadBoost.wav");

            musicPlayer.PlaySync();
            PlayBackGroundMusicLoop();
        }

        /// <summary>
        /// Plays a good sound for getting a positive bonus
        /// Is currently NOT used
        /// </summary>
        public static void PlayGoodBoost(object ignored)
        {
            musicPlayer.Stop();
            musicPlayer = new SoundPlayer("../../Sounds/getGoodBoost.wav");

            musicPlayer.PlaySync();
            PlayBackGroundMusicLoop();
        }

        /// <summary>
        /// Decided it's better that the life power up has its own sound effect
        /// Is currently NOT used
        /// </summary>
        public static void PlayGetLife(object ignored)
        {
            musicPlayer.Stop();
            musicPlayer = new SoundPlayer("../../Sounds/getLife.wav");

            musicPlayer.PlaySync();
            
            PlayBackGroundMusicLoop();
        }

        //The previous methods are supposed to be run and after that 
        //the background music should start playing again
        //are used in the main class like so:
        //ThreadPool.QueueUserWorkItem(DangerousRiver.SoundEngine.Method);
        //Where `Method` is one of the methods below
        //That's why they have to have an object parameter (which is ignored)
    }
}
